import request from "@/utils/request"
import type { SpuType, SpuImageType, SpuSaleAttrType, BaseSaleAttrType, SkuType } from "@/api/product/spu/type"
import type { Trademark } from "@/api/product/trademark/type"
import type { PageData, ResponseData } from "@/api/type"

enum API {
    HASSPU_URL = '/admin/product',
    TRADEMARK_LIST_URL = '/admin/product/baseTrademark/getTrademarkList',
    SPU_IMAGE_LIST_URL = '/admin/product/spuImageList/',
    SPU_SALE_ATTR_LIST_URL = '/admin/product/spuSaleAttrList/',
    BASE_SALE_ATTR_LIST_URL = '/admin/product/baseSaleAttrList',
    SAVE_SPU_INFO_URL = '/admin/product/saveSpuInfo',
    UPDATE_SPU_INFO_URL = '/admin/product/updateSpuInfo',
    DELETE_SPU_URL = '/admin/product/deleteSpu/',
    SAVE_SKU_INFO_URL = '/admin/product/saveSkuInfo',
    FIND_SKU_List_URL = '/admin/product/findBySpuId/'
}

const reqHasSpu = (page: number, limit: number, category3Id: number | undefined) => {
    return request.get<any, ResponseData<PageData<SpuType>>>(API.HASSPU_URL + `/${page}/${limit}?category3Id=${category3Id}`)
}

const reqTrademarkList = () => {
    return request.get<any, ResponseData<Trademark[]>>(API.TRADEMARK_LIST_URL)
}

const reqSpuImageList = (spuId: number) => {
    return request.get<any, ResponseData<SpuImageType[]>>(API.SPU_IMAGE_LIST_URL + `${spuId}`)
}

const reqSpuSaleAttrList = (spuId: number) => {
    return request.get<any, ResponseData<SpuSaleAttrType[]>>(API.SPU_SALE_ATTR_LIST_URL + `${spuId}`)
}

const reqBaseSaleAttrList = () => {
    return request.get<any, ResponseData<BaseSaleAttrType[]>>(API.BASE_SALE_ATTR_LIST_URL)
}

const reqSaveSpuInfo = (spuInfo: SpuType) => {
    return request.post<any, ResponseData<any>>(API.SAVE_SPU_INFO_URL, spuInfo)
}

const reqUpdateSpuInfo = (spuInfo: SpuType) => {
    return request.post<any, ResponseData<any>>(API.UPDATE_SPU_INFO_URL, spuInfo)
}

const reqDeleteSpuInfo = (spuId: number) => {
    return request.delete<any, ResponseData<any>>(API.DELETE_SPU_URL + `${spuId}`)
}

const reqSaveSkuInfo = (data: SkuType) => {
    return request.post<any, ResponseData<any>>(API.SAVE_SKU_INFO_URL, data)
}

const reqFindSkuList = (spuId: number) => {
    return request.get<any, ResponseData<SkuType[]>>(API.FIND_SKU_List_URL + `${spuId}`)
}

export {
    reqHasSpu,
    reqTrademarkList,
    reqSpuImageList,
    reqSpuSaleAttrList,
    reqBaseSaleAttrList,
    reqSaveSpuInfo,
    reqUpdateSpuInfo,
    reqDeleteSpuInfo,
    reqSaveSkuInfo,
    reqFindSkuList
}